<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ page import="com.daogou.model.TBItems"%>
<%@ page import="com.inter.Taobao"%>
<%@ page import="com.inter.Taobao"%>
<%@ page import="com.taobao.api.ApiException"%>
<%@ page import="com.taobao.api.domain.TaobaokeItem"%>
<%@ page import="java.util.List"%><%@page import="java.net.URLEncoder"%>

<%
    request.setCharacterEncoding("utf-8");
	response.setCharacterEncoding("utf-8");
    List<TaobaokeItem> re = (List<TaobaokeItem>)request.getAttribute("result");
    
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>搜索到---<%= request.getAttribute("pages")%>页数据</title>

<style type="text/css">
   a:link{
      text-decoration: none;
      color: #ff9923;
      
   }
   a:HOVER {
	  text-decoration: none;
      color: #ff7788;
      background-color: #00ffff;
   }

</style>
</head>
<body>

<form method="post" action="taobaosearch">
  <input type="text" value="女装" name="key">
  <input type="submit" /> 
</form>
   <%
   //当前第几页
      long cpage =  Long.parseLong(request.getAttribute("cpage").toString());
      String key = request.getAttribute("key").toString();
      key = URLEncoder.encode(key);
      //总页数100000
      long totalpages = Long.parseLong(request.getAttribute("pages").toString());
      
      if(cpage>1){
                 out.print("<a href='?cpage="+(cpage-1)+"&key="+key+"'>上一页</a>"+" ");
       }
      
      for(int i=1;i<totalpages;i++){
           
           if(i==cpage){
             //如果现在是这一页
                out.print(i+" ");
           }else{
           		out.print("<a href='?cpage="+i+"&key="+key+"'>"+i+"</a>"+" ");
           }
           
           if(i>10 ){
               out.print("...");
               break;
           }
        }
       if(cpage+1<totalpages){
             out.print("<a href='?cpage="+(cpage+1)+"&key="+key+"'>下一页</a>"+" ");
       }
    %>
   <table>
     <tr><th>商品名称</th><th>商品图片</th><th>商品返利</th><th>购买地址</th></tr>
      <%
      for(TaobaokeItem item:re){
          out.print("<tr> <td>");
          out.print(item.getTitle());
          out.print("</td><td>");
          out.print("<img src=\""+item.getPicUrl()+"_120x120.jpg\">");
          out.print("</td><td>");
          out.print(item.getPrice()+"元/返回"+item.getCommission());
          out.print("</td><td>");
          out.print("<a href=\""+item.getClickUrl()+"\" target=\"_blank\">点击购买</a>");
          out.print("</td> </tr>");
      }
     %>
     
   </table>
   
</body>
</html>